<?php
include("../mysql_connect.php");
include("../error/upload.php");

$xml = simplexml_load_file('php://input');

foreach( $xml->attributes( ) as $attr)
{
	$AttrArray[] = $attr;
}
$NoteId = $AttrArray[0];
$Text = $AttrArray[1];
$MediaId = $AttrArray[2];
$AxisX = $AttrArray[3];
$AxisY = $AttrArray[4];
$UserName = $AttrArray[5];

//Create New Note
if ($NoteId=="") {
	
	$sltSqlCommand = "SELECT idUSER FROM USER WHERE Email = '".$UserName."'";
 	$sltResult = mysql_query($sltSqlCommand);
 	$sltRow = mysql_fetch_array($sltResult);
 	
 	$userId = $sltRow['idUSER'];
	
	$strSqlCommand = "INSERT INTO notes (NoteText, USER_idUSER, MEDIA_idMEDIA, AxisX, AxisY) 
						VALUES ('".$Text."', '".$userId."', '".$MediaId."', '".$AxisX."','".$AxisY."')";
	if (!mysql_query($strSqlCommand)) {
		die(mysql_error());
	 	echo "<Error Message=\"".mysql_error()."\" Domain=\"Configuration\" />";
		saveError("Notes", NULL, date("Y-m-d H:i:s"), mysql_error());
	 	return;
	}
	
	if (mysql_insert_id()!=0) {
		$NoteId = mysql_insert_id();
		echo '<Success Message="The requested Information was accepted" NoteId="'.$NoteId.'" Domain="Configuration" />';
	}
}
//Modify Note
else {
	
	$strSqlCommand = "UPDATE notes SET NoteText='".$Text."' WHERE idNOTES='".$NoteId."'";
	if (!mysql_query($strSqlCommand)) {
	 echo '<Error Message="The requested Information was not found" Domain="Configuration" />';
	 saveError("Notes", NULL, date("Y-m-d H:i:s"), "The requested Information was not found");
	 return;
	}
	
	echo '<Success Message="The requested Information was accepted" Domain="Configuration" />';
}
?>
